package org.graduation.project.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.graduation.model.common.project.Phase;
import org.graduation.model.common.project.ProjectUserTable;
import org.graduation.model.common.project.Task;
import org.graduation.model.common.project.TaskAndUserTable;
import org.springframework.stereotype.Component;

@Component
public class MybatisPlusWrapperFactory {

    public static LambdaQueryWrapper<ProjectUserTable> existRepeatInviteUser(ProjectUserTable projectUserTable) {
        LambdaQueryWrapper<ProjectUserTable> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ProjectUserTable::getUid, projectUserTable.getUid())
                .eq(ProjectUserTable::getPid, projectUserTable.getPid());
        return lambdaQueryWrapper;
    }

    public static LambdaQueryWrapper<Phase> getAllPhaseByPId(Long pId) {
        LambdaQueryWrapper<Phase> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Phase::getPId, pId);
        return lambdaQueryWrapper;
    }

    public static LambdaQueryWrapper<ProjectUserTable> getProjectAndUser(Long pId) {
        return new LambdaQueryWrapper<ProjectUserTable>().eq(ProjectUserTable::getPid, pId);
    }

    public static LambdaQueryWrapper<Task> getTaskByPhaseId(Long phaseId) {
        return new LambdaQueryWrapper<Task>().eq(Task::getPhaseId, phaseId);
    }

    public static LambdaQueryWrapper<TaskAndUserTable> deleteTaskAndUser(Task task){
        return new LambdaQueryWrapper<TaskAndUserTable>().eq(TaskAndUserTable::getTaskId, task.getTaskId());
    }
}
